﻿using System.Text.RegularExpressions;
using com.fukefu.source;

namespace com.fukefu.info.b2b.auto
{
    public class WaaKu : Information
    {
        public override bool Login(string name, string pass, string vcode)
        {
            ParametersData pd = new ParametersData("gb2312");
            pd.Add("identity", name);
            pd.Add("pwd", pass);
            pd.Add("submit1", "确 认 登 录");
            string html = source.Post("http://www.waaku.com/Login2.html", pd.Read(), "http://www.waaku.com/login.html?");
            if (html.IndexOf("登录成功，三秒后转到后台页...") != -1)
            {
                return true;
            }
            return false;
        }

        public override InformationResult PostArticle(string title, string content, string vcode)
        {
            title = tek.Get(title);
            CookieFactory.GetInstance().Add("waaku.com", "fbtjwaaku=1");
            InformationResult result = new InformationResult();
            if (!source.Post("http://post.waaku.com/kh/cktitle2.asp", "regid=" + MyFunction.Encode(title), "http://post.waaku.com/kh/postadfb15_202.html").Equals("1"))
            {
                result.Content = "发布标题重复!";
                return result;
            }
            ParametersData pd = new ParametersData("gb2312");
            pd.Add("subject", title);
            pd.Add("txtcontent", MyFunction.ToText(content));
            string html = source.Post("http://post.waaku.com/kh/AddInfoEnd" + site.TypeId[0] + "_" + site.TypeId[1] + ".html", pd.Read(), "http://post.waaku.com/kh/postadfb" + site.TypeId[0] + "_" + site.TypeId[1] + ".html");
            if (html.IndexOf("该信息已发布成功，管理员会在24小时内审核") != -1)
            {
                result.Code = 1;
                result.Content = Regex.Match(html, "<a href=\"(http://www.waaku.com/InfoView[^\"]+)\" target=\"_blank\">请点击查看</a>").Groups[1].Value;
            }
            return result;
        }
    }
}
